/**
 * 
 */
package com.scpii.universal.struts.manage;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.doone.comm.paginaction.Pagination;
import com.scpii.universal.action.BaseAction;
import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.hibernate.entity.ClientUserTab;
import com.scpii.universal.service.ClientUserService;
import com.scpii.universal.util.UtilTool;



/**
 * universalWeb
 * @author weny
 * 2012-7-9下午05:20:49
 */
@Controller
@Scope("prototype")
public class ClientUserAction extends BaseAction {
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 4629317011625914415L;
	@Resource
	private ClientUserService clientUserService;

	
	private Pagination page = new Pagination();
	
	private List<ClientUserTab> clientUserList;
	
	private ClientUserTab clientUserInfo;
	
    private ClientUserTab condition;
	
	private ClientUserTab clientUseraddInfo;
	/**
	 * 获取会员信息列表
	 * @return
	 * @author weny
	 * 2012-7-20上午10:47:26
	 */
	public String getClientUserPage(){
		//modify by zhangqiang 20120725
		//UserInfoDto userInfoDto=(UserInfoDto) session.getAttribute("userInfoDto");
		if(condition==null){
			condition=new ClientUserTab();
		}
        condition.setIntAppId(getUserInfo().getAppId());
		try {
			
			//获取返回信息的条数
			Integer recordCount =clientUserService.getClientUserRecode(condition);
			
			if (getSelectPerPage("page") == -1) {
				page.setPageRecord(GenericConstants.PAGE_NO);
			} 
			else {
				page.setPageRecord(getSelectPerPage("page"));
			}
			//判断是否是第一次查询
			if (getQueryFlag("page") == -1) {
				page.setTotalRecord(recordCount);
			} 
			else {
				page.setTotalRecord(getQueryFlag("page"));
			}
			setPageParameters(page, "page");
	        //获取页面返回list
			clientUserList = clientUserService.getClientUserListPage(condition,page.getCurrentPage(), page.getPageStart(), page.getPageRecord());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
    
   
	/**
	 * 获取分享信息
	 * @return
	 * @author weny
	 * 2012-7-13上午10:00:26
	 */
	public String getClientUser(){
		String favoritesId=request.getParameter("intUserId");
		clientUserInfo=clientUserService.get(Integer.valueOf(favoritesId));
		return SUCCESS;
	}
    /**
     * 删除客户端用户信息
     * @return
     * @author weny
     * 2012-7-19下午03:06:13
     */
	public String delClientUser(){
		String intUserId=request.getParameter("intUserId");
		ClientUserTab clientUserTab=clientUserService.get(Integer.valueOf(intUserId));
		clientUserTab.setIntDeleteSign(GenericConstants.DELETE_SIGN_DELETED);
		clientUserService.update(clientUserTab);
		return SUCCESS;
	}
	/**
	 * 编辑客户端信息
	 * @return
	 * @author weny
	 * 2012-7-19下午06:26:54
	 */
	public String editClientUser(){
		clientUserInfo.setDatUpdateDatetime(UtilTool.dateToString(new Date()));
		clientUserService.update(clientUserInfo);
		return SUCCESS;
	}
	/**
	 * 添加会员用户信息
	 * @return
	 * @author weny
	 * 2012-7-20上午10:40:05
	 */
	public String addClientUser(){
		//modify by zhangqiang 20120725
		//UserInfoDto userInfoDto=(UserInfoDto) session.getAttribute("userInfoDto");
		clientUseraddInfo.setIntAppId(getUserInfo().getAppId());
		clientUseraddInfo.setIntDeleteSign(GenericConstants.DELETE_SIGN_EXIST);
		clientUseraddInfo.setDatUpdateDatetime(UtilTool.dateToString(new Date()));
		clientUserService.save(clientUseraddInfo);
		return SUCCESS;
	}
	//======================get() set()方法
	public Pagination getPage() {
		return page;
	}


	public void setPage(Pagination page) {
		this.page = page;
	}


	public List<ClientUserTab> getClientUserList() {
		return clientUserList;
	}


	public void setClientUserList(List<ClientUserTab> clientUserList) {
		this.clientUserList = clientUserList;
	}


	public ClientUserTab getClientUserInfo() {
		return clientUserInfo;
	}


	public void setClientUserInfo(ClientUserTab clientUserInfo) {
		this.clientUserInfo = clientUserInfo;
	}


	public ClientUserTab getCondition() {
		return condition;
	}


	public void setCondition(ClientUserTab condition) {
		this.condition = condition;
	}


	public ClientUserTab getClientUseraddInfo() {
		return clientUseraddInfo;
	}


	public void setClientUseraddInfo(ClientUserTab clientUseraddInfo) {
		this.clientUseraddInfo = clientUseraddInfo;
	}





	


	

	
	
}
